<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>

    let counts = (arr, value) => arr.reduce((a, v) => v === value ? a + 1 : a + 0, 0);

    console.log('"苏100"出现的次数是：' + counts(["苏100", "沪200", "苏100", "京300", "苏100", "京300"], "苏100"));

    // 用reduce时：
    let arr = ["苏100", "沪200", "苏100", "京300", "苏100", "京300"];

    function getRepeatNum() {
        return arr.reduce(function (prev, next) {
            prev[next] = (prev[next] + 1) || 1;
            return prev;
        }, {});
    }

    console.table(getRepeatNum());


    // 不用reduce
    let arr2 = ["苏100", "沪200", "苏100", "京300", "苏100", "京300"];

    function getRepeatNum2() {
        let obj = {};
        for (let i = 0, l = arr.length; i < l; i++) {
            let item = arr[i];
            obj[item] = (obj[item] + 1) || 1;
        }
        return obj;
    }

    console.table(getRepeatNum2());


</script>
</body>
</html>